package org.jvcs.common;

import org.jvcs.common.*;

import java.util.*;
import java.io.*;
import java.security.*;
import java.math.*;


public class MD5SumUtils {


public static String get(String inFile) {
	MessageDigest digest = null;
	File f = null;
	InputStream is =null;
	String output = null;
	try {
		digest = MessageDigest.getInstance("MD5");
		f = new File(inFile);
		is = new FileInputStream(f);				
		byte[] buffer = new byte[8192];
		int read = 0;
	
		while( (read = is.read(buffer)) > 0) {
			digest.update(buffer, 0, read);
		}		
		byte[] md5sum = digest.digest();
		BigInteger bigInt = new BigInteger(1, md5sum);
		output = bigInt.toString(16);
		//System.out.println("MD5: " + output);
		return output;
	}
	catch(Exception e) {
		System.out.println("Unable to create MD5SUM: "+e.toString());
	}
	finally {
		try {
			is.close();
		} catch(Exception e) {
			System.out.println("Unable to (close input stream) create MD5SUM: "+e.toString());
		}
	}	
	return output;
}
}
